﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ecreate.Business;
using Ecreate.Model;

namespace Ecreate.Web.systemanage.productclass
{
    public partial class addproductclass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.hid_type.Value = Request.QueryString["type"];
                this.hid_id.Value = Request.QueryString["classid"];

                if (this.hid_type.Value == "updatenode")
                {

                    ProductClassService service = new ProductClassService();
                    ProductClass model = service.getProductClassByClassID(this.hid_id.Value);
                    this.txt_classname.Text = model.Classname;
                    this.Submit1.Value = "保存";
                }

                else
                {

                    this.Submit1.Value = "添加";
                }


            }
            else
            {
                string type = this.Request.Form["hid_type"];
                if (type != null)
                {
                    if (type == "addroot")
                    {
                        ProductClass p = new ProductClass();
                        p.Parentclassid = "-1";
                        p.Classname = this.Request.Form["txt_classname"];
                        ProductClassService service = new ProductClassService();
                        bool ret = service.Insert(p);
                        if (!ret)
                        {
                            //HtmlHelper.ShowMessage(this, "产品类别名称重复！");
                            Response.Write("<script type=\"text/javascript\" language=\"javascript\">          alert('产品类别名称重复！')　　; </script>");
                            //Response.Write("<script type=\"text/javascript\" language=\"javascript\">          window.parent.frames[\"productclassIframe\"].location.reload()　　; </script>");
                            //Response.Write("<script type=\"text/javascript\" language=\"javascript\">          window.parent.frames[\"productclassDtlIframe\"].location=\"/systemanage/client.aspx\"　　; </script>");
                            return;
                        }
                    }
                    else if(type=="addnode")
                    {
                        ProductClass p = new ProductClass();
                        p.Parentclassid = this.Request.Form["hid_id"];
                        p.Classname = this.Request.Form["txt_classname"];
                        ProductClassService service = new ProductClassService();
                        bool ret=service.Insert(p);
                        if (!ret)
                        {
                            //HtmlHelper.ShowMessage(this, "产品类别名称重复！");
                            Response.Write("<script type=\"text/javascript\" language=\"javascript\">          alert('产品类别名称重复！')　　; </script>");
                            //Response.Write("<script type=\"text/javascript\" language=\"javascript\">          window.parent.frames[\"productclassIframe\"].location.reload()　　; </script>");
                            //Response.Write("<script type=\"text/javascript\" language=\"javascript\">          window.parent.frames[\"productclassDtlIframe\"].location=\"/systemanage/client.aspx\"　　; </script>");
                            return;
                        }
                    }
                    else if (type == "addchildnode")
                    {
                        ProductClass p = new ProductClass();
                        p.Parentclassid = this.Request.Form["hid_id"];
                        p.Classname = this.Request.Form["txt_classname"];
                        ProductClassService service = new ProductClassService();
                        service.Insert(p);
                    }
                    else if (type == "updatenode")
                    {
                        ProductClass p = new ProductClass();
                        p.Classid = this.Request.Form["hid_id"];
                        p.Classname = this.Request.Form["txt_classname"];
                        ProductClassService service = new ProductClassService();
                        service.Update(p);

                    }
                    Response.Write("<script type=\"text/javascript\" language=\"javascript\">          alert('数据保存成功!')　　; </script>");
                    Response.Write("<script type=\"text/javascript\" language=\"javascript\">          window.parent.frames[\"productclassIframe\"].location.reload()　　; </script>");
                    Response.Write("<script type=\"text/javascript\" language=\"javascript\">          window.parent.frames[\"productclassDtlIframe\"].location=\"/systemanage/client.aspx\"　　; </script>");
                }
            }
        }
    }
}
